package com.kenans.contorller;

import com.kenans.common.JsonResult;
import com.kenans.dao.CityDao;
import com.kenans.entity.City;
import com.kenans.service.CityService;
import com.kenans.vo.VCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author KENANS
 * @date 2020-8-26 17:42
 * @Version 1.0
 */
@Controller
@RequestMapping("/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 这个方法是根据pid获取，对应的城市
     * @param pid
     * @return
     */
    @RequestMapping("/select.do")
    @ResponseBody
    public JsonResult findAllByPid(Integer pid) {
        List<City> cities = cityService.findAllByPid(pid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(1);
        jsonResult.setInfo(cities);
        return jsonResult;
    }

    /**
     * 要在租车的页面显示出发地，这个是获取上一个页面传递过来的getid backid.
     * @param backid
     * @param getid
     * @return
     */
    @RequestMapping("/citys.do")
    @ResponseBody
    public JsonResult findById(Integer getid, Integer backid) {
        City getCity = cityService.findById(getid);
        City backCity = cityService.findById(backid);
        VCity vCity = new VCity(getCity, backCity);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setInfo(vCity);
        jsonResult.setCode(1);
        return jsonResult;
    }
}
